import os
import sys
import time

import pytest

from apirunner.pytest_load_yaml import plugin


def main():
    """apirunner 框架主运行函数"""
    get_cmd_command = []
    for arg in sys.argv:
        if arg.startswith('-'):
            get_cmd_command.append(arg)
    report_name = time.strftime('%Y年%m月%d日_%H时%M分%S秒', time.localtime())
    test_path = os.path.join(os.path.dirname(__file__), 'testing/test_api.py')
    pytest_arg = [
        f'{test_path}',
        f'--html=apirunner/reports/{report_name}.html', '--self-contained-html',
    ]
    pytest_arg.extend(get_cmd_command)
    pytest.main(pytest_arg, plugins=[plugin])
